<template>
    <div class="login-container">
        <div class="container">
            <div class="screen">
                <div class="screen__content">
                    <transition name="fade" mode="out-in">
                        <div class="form-container" :key="state.status">
                            <account v-if="state.status === 'login'" :tenant-info="state.tenantInfo"/>
                            <register v-if="state.status === 'register'" :tenant-info="state.tenantInfo"/>
                        </div>
                    </transition>
                    <div class="social-login">
                        <h3>后台系统</h3>
                        <!-- <p class="register-tip">
                            <template v-if="state.status === 'login'">
                                还没有账号？
                                <a @click="state.status = 'register'" class="register-link">立即注册</a>
                            </template>
                            <template v-else>
                                已有账号？
                                <a @click="state.status = 'login'" class="register-link">立即登录</a>
                            </template>
                        </p> -->
                    </div>
                </div>
                <div class="screen__background">
                    <span class="screen__background__shape screen__background__shape4"></span>
                    <span class="screen__background__shape screen__background__shape3"></span>		
                    <span class="screen__background__shape screen__background__shape2"></span>
                    <span class="screen__background__shape screen__background__shape1"></span>
                </div>		
            </div>
        </div>
    </div>
</template>


<script setup lang="ts">
import {reactive,onMounted} from 'vue'
import account from './components/account.vue'
import {apiSysTenantListGet} from '@/api/sys/sysTenant.ts'
import type{TenantInfoType } from './types/index'
import register from './components/register.vue'

interface StateType {
	activeKey:string
	tenantInfo:TenantInfoType,
	status:string
}

const state = reactive<StateType>({
    activeKey:"account",
	tenantInfo:{
		id: undefined,
		list: [],
	},
	status:"login"
})

const getTenantInfo = async ()=>{
	let res = await apiSysTenantListGet()
	state.tenantInfo.list = res.data.result
	const host = location.host.toLowerCase(); //当前ip和端口
	const tenant = state.tenantInfo.list.find((item:any)=> item.host == host) as any //当前租户匹配成功进行赋值
	if(tenant?.value){
		state.tenantInfo.id = tenant.value
	}
}

onMounted(async()=>{
	await getTenantInfo()
})
</script>

<style lang="scss" scoped>
@import url('https://fonts.googleapis.com/css?family=Raleway:400,700');

.login-container {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
	background: linear-gradient(90deg, #C7C5F4, #776BCC);	
	display: flex;
	align-items: center;
	justify-content: center;	
}

.container {
	display: flex;
	align-items: center;
	justify-content: center;
    width: 100%;
    height: 100%;
}

.screen {		
	background: linear-gradient(90deg, #5D54A4, #7C78B8);		
	position: relative;	
	height: 600px;
	width: 480px;	
	box-shadow: 0px 0px 24px #5C5696;
}

.screen__content {
	z-index: 1;
	position: relative;	
	height: 100%;
    padding: 30px;
    margin-top: 50px;
    .ant-tabs{
        :deep(.ant-tabs-nav-list){
            width:100%;
            .ant-tabs-tab{
                flex:1;
                .ant-tabs-tab-btn{
                    flex:1;
                    text-align: center
                }
            }
        }
    }
}

.screen__background {		
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 0;
	-webkit-clip-path: inset(0 0 0 0);
	clip-path: inset(0 0 0 0);	
}

.screen__background__shape {
	transform: rotate(45deg);
	position: absolute;
}

.screen__background__shape1 {
	height: 520px;
	width: 520px;
	background: #FFF;	
	top: -50px;
	right: 120px;	
	border-radius: 0 72px 0 0;
}

.screen__background__shape2 {
	height: 220px;
	width: 220px;
	background: #6C63AC;	
	top: -172px;
	right: 0;	
	border-radius: 32px;
}

.screen__background__shape3 {
	height: 540px;
	width: 190px;
	background: linear-gradient(270deg, #5D54A4, #6A679E);
	top: -24px;
	right: 0;	
	border-radius: 32px;
}

.screen__background__shape4 {
	height: 400px;
	width: 200px;
	background: #7E7BB9;	
	top: 420px;
	right: 50px;	
	border-radius: 60px;
}



.social-login {	
	position: absolute;
	height: 140px;
	width: 160px;
	text-align: center;
	bottom: 0px;
	right: 0px;
	color: #fff;

    .register-tip {
        margin-top: 10px;
        font-size: 14px;
        
        .register-link {
            color: #fff;
            text-decoration: underline;
            cursor: pointer;
            margin-left: 5px;
            transition: all 0.3s;
            
            &:hover {
                opacity: 0.8;
            }
        }
    }
}

.social-icons {
	display: flex;
	align-items: center;
	justify-content: center;
}

.social-login__icon {
	padding: 20px 10px;
	color: #fff;
	text-decoration: none;	
	text-shadow: 0px 0px 8px #7875B5;
}

.social-login__icon:hover {
	transform: scale(1.5);	
}

// 添加过渡动画样式
.fade-enter-active,
.fade-leave-active {
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.fade-enter-from {
    opacity: 0;
    transform: translateX(20px);
}

.fade-leave-to {
    opacity: 0;
    transform: translateX(-20px);
}
</style>